var BlogMessageBox = Class.create();
Object.extend(BlogMessageBox, MessageBox);
Object.extend(BlogMessageBox, {
	TYPE_PHOTO_PROMPT: 'type_blog_prompt'
});
Object.extend(BlogMessageBox.prototype, MessageBox.prototype);
Object.extend(BlogMessageBox.prototype, {
	initialize: function(type, message, title, callback){
		this.type = type;
		this.callback = callback;
		var template = new Template($('template_message_panel_'+type).innerHTML.replace('<!--','').replace('-->',''));
		var html = template.evaluate({message: message, title: title});
		new Insertion.Top($(document.body), html);
		this.show();
		this.bindHandlers(type);
		this.bindHandlers2(type);
	},
	bindHandlers2: function(){
		switch(this.type){
			case BlogMessageBox.TYPE_PHOTO_PROMPT:
				var btnOk = $$('#panel .ok')[0];
				var btnCancel = $$('#panel .cancel')[0];
				btnOk.observe('click', this.onOkClick.bindAsEventListener(this));
				btnCancel.observe('click', this.onCancelClick.bindAsEventListener(this));
			break;
		}
	},
	show: function(){
		//this.hideSelect();
		$('panel').setStyle({left: '0', top: '0', height: $(document.documentElement).scrollHeight+"px"});
		$('panel').show();

		var msg = $$('#panel .panel_wrap')[0];
		var clientHeight = document.documentElement.clientHeight ;
		var clientWidth = document.documentElement.clientWidth;
		var width = msg.getWidth();
		var height = msg.getHeight();
		var top = (clientHeight - height)/2 + document.documentElement.scrollTop - (clientHeight - height)/2 * 0.3;
		var left = (clientWidth - width)/2;
		msg.absolutize().setStyle({top: top + "px", left: left + "px"});
	//	$$('select').each(function(item){ item.hide();});
	}
});

function showCreateCategory(content,title){
	var box = new BlogMessageBox(BlogMessageBox.TYPE_PHOTO_PROMPT, title, content, {ok: function(){
	var cname = $$('#panel input[name=cname]')[0].value;
	//alert(album_titile+'\n'+album_address+'\n'+album_info+'\n'+album_srank+'\n')
	//alert(v1 + ',' + v2);
	if(cname.length > 6){
			new MessageBox(MessageBox.TYPE_MESSAGE,'分类名称长度不能超过6个汉字或者字符', '', {});
			return false;
	}
	
		if(!cname){
			$('category_title').insert("<span class=\"ufriend-tip\" id='prompt_msg'>名称不能为空</span>");
			//new Deletion('prompt_msg', 3000);
	
		}else{
			new Ajax.Request('/?_app=blog&_controller=category&_action=add&ajax=1',{
				parameters: $H({cname:cname}),
				onComplete: function(transport){
					if(transport.responseText>0)
						insertCategory(transport.responseText,cname);
					//location.reload();
					else
						new MessageBox(MessageBox.TYPE_MESSAGE,'创建失败，稍后再试', '', {});
				}
			});
		}
	}});
}

function insertCategory(id,cname){
	var category = document.getElementById('category');
     /// 使用W3C标准语法为SELECT添加Option
	var objOption = document.createElement("OPTION");
	objOption.value=id;
	objOption.text=cname ;
	category.options.add(objOption);
	objOption.selected =true;
}

